added Feb 2001 SDK
[windows-sources.git] / shared source / sscli20 / samples / pigui / tk / delegatewrappers.cs
blobdee39d54ab999c3e02a89fb17436520d29c6fa77
1 //------------------------------------------------------------------------------
2 // <copyright file="DelegateWrappers.cs" company="Microsoft">
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 // </copyright>
14 //------------------------------------------------------------------------------
16 using System;
17 using System.Runtime.InteropServices;
19 namespace SharedSourceCLI.TK
21 internal class TclAppInitProcWrapper {
23 TclInterp _interp;
24 TclAppInitProc _proc;
25 Tcl_AppInitProc _callback;
27 internal TclAppInitProcWrapper(TclInterp interp, TclAppInitProc proc) {
28 _interp = interp;
29 _proc = proc;
30 unsafe { _callback = new Tcl_AppInitProc(this.CallbackProc); }
33 internal Tcl_AppInitProc Callback {
34 get { return _callback; }
37 private unsafe int CallbackProc(Tcl_Interp* interp)
39 try {
40 _proc(_interp);
42 catch (Exception) {
43 return TclNative.TCL_ERROR;
46 return TclNative.TCL_OK;
50 internal class TclCmdProcWrapper {
52 TclInterp _interp;
53 TclCmdProc _proc;
54 Tcl_CmdProc _callback;
56 internal TclCmdProcWrapper(TclInterp interp, TclCmdProc proc) {
57 _interp = interp;
58 _proc = proc;
59 unsafe { _callback = new Tcl_CmdProc(this.CallbackProc); }
62 internal Tcl_CmdProc Callback {
63 get { return _callback; }
66 private unsafe int CallbackProc(IntPtr clientData,
67 Tcl_Interp* interp, int argc, char** argv)
69 try {
70 string[] arr = new string[argc];
71 for(int i=0; i<argc; i++)
73 arr[i] = Marshal.PtrToStringAnsi((IntPtr)argv[i]);
76 _proc(_interp, arr);
78 catch (Exception) {
79 return TclNative.TCL_ERROR;
82 return TclNative.TCL_OK;
86 internal class TclCmdDeleteProcWrapper {
88 TclInterp _interp;
89 TclCmdDeleteProc _proc;
90 Tcl_CmdDeleteProc _callback;
91 Object _deletee;
93 internal TclCmdDeleteProcWrapper(TclInterp interp, TclCmdDeleteProc proc, Object deletee) {
94 _interp = interp;
95 _proc = proc;
96 unsafe { _callback = new Tcl_CmdDeleteProc(this.CallbackProc); }
97 _deletee = deletee;
99 _interp.AddKeepAlive(this);
100 _interp.AddKeepAlive(_deletee);
103 internal Tcl_CmdDeleteProc Callback {
104 get { return _callback; }
107 private unsafe int CallbackProc(IntPtr clientData)
109 try {
110 _interp.RemoveKeepAlive(_deletee);
111 _interp.RemoveKeepAlive(this);
113 if (_proc != null)
114 _proc();
116 catch (Exception) {
117 return TclNative.TCL_ERROR;
120 return TclNative.TCL_OK;